package com.funfitnessapp;
/**
 * 
 * @author Kyle Lewis
 * @date October 9, 2012
 * 
 * Stopwatch Object
 *
 */
public class StopWatch
{
        /** Class Variables **/
        private long startTime;
        private long lapStartTime;
        private long stopTime;
        private double[] laps;
        private int lapCount;
        
        /**
         * Constructor
         */
        public StopWatch()
        {
                this.startTime = 0;
                this.lapStartTime = 0;
                this.stopTime = 0;
                this.laps = new double[50];
                this.lapCount = 0;
        }
        
        /**
         * Starts the Stopwatch
         */
        public void start()
        {
                this.startTime = System.currentTimeMillis();
                this.lapStartTime = startTime;
        }
        
        /**
         * Stops the Stopwatch
         */
        public double stop()
        {
                this.stopTime = System.currentTimeMillis();
                
                this.laps[this.lapCount] = 
                        ((int)((this.stopTime - this.lapStartTime) / 10)) / 100.0;
                this.lapCount++;
                
                return this.laps[this.lapCount - 1];
        }
        
        /**
         * Pauses the Stopwatch
         */
        public void pause()
        {
                // TODO
        }
        
        /**
         * Starts a new lap
         */
        public void newLap()
        {
                long newLapTime = System.currentTimeMillis();
                
                this.laps[this.lapCount] = 
                        ((int)((newLapTime - this.lapStartTime) / 10)) / 100.0;
                this.lapCount++;
                
                this.lapStartTime = newLapTime;
        }
        
        /**
         * Returns the total elapsed time
         * 
         * @return time in seconds, 2 decimal places
         */
        public double getTotalElapsedTime()
        {
                long currentTime = System.currentTimeMillis();
                
                return ((int) ((currentTime - this.startTime) / 10)) / 100.0;
        }
        
        /**
         * Returns the elapsed time of the current lap
         * 
         * @return time in seconds, 2 decimal places
         */
        public double getLapElapsedTime()
        {
                long currentTime = System.currentTimeMillis();
                
                return ((int) ((currentTime - this.lapStartTime) / 10)) / 100.0;
        }
        
        /**
         * Returns the array with each of the lap times
         * 
         * @return an array of doubles
         */
        public double[] getLaps()
        {
                return this.laps;
        }
        
        /**
         * Returns the number of laps stored
         * 
         * @return an int of laps
         */
        public int getLapCount()
        {
                return this.lapCount;
        }
}